package luzhin;

import java.io.*;

/**
 * Move.
 * Doesn't remember promotion!
 * @author lacungus
 *
 */
//TODO remember promotion
public class Move implements Serializable {
	private static final long serialVersionUID = 38949823L;
	private int from;
	private int to;

	/**
	 * Constructs a move from notation.
     * Don't check notation for being valid.
	 * @param notation string for the move (example: "e2e4").
	 */
	public Move(String notation) {
		from = Position.getPosition(notation.substring(0, 2));
		to = Position.getPosition(notation.substring(2, 4));		
	}
	
	/**
	 * @param from position a piece moved from
     * @param to position a piece moved to
	 */
	public Move(int from, int to) {
		this.from = from;
		this.to = to;
	}

	public Move(int from, int to, int castling) {
		this.from = from;
		this.to = to;
	}

    @Override
	public boolean equals(Object m) {
        Move move = (Move) m;
		return (this.from == move.from && this.to == move.to);
	}

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 17 * hash + this.from;
        hash = 17 * hash + this.to;
        return hash;
    }
	
	public int getFrom() {
		return from;
	}

	public int getTo() {
		return to;
	}	
	
    @Override
	public String toString() {
		String s = "";
		s += Position.positionToString(from);
		s += Position.positionToString(to);
		return s;
	}
}
